package com.netty.study.handler;

import com.alibaba.fastjson.JSONObject;
import com.netty.study.dto.UserMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

/**
 * string转userMessage对象
 */
public class StringToMessageDecoderHandler extends MessageToMessageDecoder<String> {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, String s, List<Object> list) throws Exception {
        UserMessage userMessage = JSONObject.toJavaObject(JSONObject.parseObject(s), UserMessage.class);
        list.add(userMessage);
    }
}